//
//  OEHomeCollectionReusableHeader.m
//  OneEightyNine
//
//  Created by apple on 2019/3/6.
//  Copyright © 2019 stoneobs. All rights reserved.
//

#import "OEHomeCollectionReusableHeader.h"
#import "STPageView.h"
@interface OEHomeCollectionReusableHeader()
@property(nonatomic, strong) STPageView                     *pageView;/**<  */
@property(nonatomic, strong) STPageControl                     *pageControll;/**<  */

@end
@implementation OEHomeCollectionReusableHeader
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self configSubView];
    }
    return self;
}
#pragma mark --configSubView
- (void)configSubView{
   
    
   self.cateButton = [[STButton alloc] initWithFrame:CGRectMake(10, 0, 111, 25)
                                                  title:@""
                                             titleColor:UIColor.whiteColor
                                              titleFont:12
                                           cornerRadius:0
                                        backgroundColor:nil
                                        backgroundImage:[UIImage imageNamed:@"222×50背景"]
                                                  image:nil];
    [self addSubview:self.cateButton];
    self.cateButton.titleEdgeInsets = UIEdgeInsetsMake(0, 5, 0, 0);
}
- (void)configBanner{
    [self.pageView removeFromSuperview];
    [self.pageControll removeFromSuperview];
    __weak typeof(self) weakSelf =  self;
    self.pageView = [[STPageView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 230)];
    self.pageView.autoMoveDuring = 4;
    self.pageView.pageControl.hidden = YES;
    self.pageView.pageControl.height = 200;
    self.pageView.backgroundColor = UIColor.clearColor;
    NSMutableArray * imageUrlArray = NSMutableArray.new;
    for (OEAdverModel * model in self.model.bannerArray) {
        [imageUrlArray addObject:model.image];
    }
    self.pageView.imageUrlArray = imageUrlArray;
    self.pageView.animationType = FSPagerViewTransformerTypeZoomOut;
    [self.pageView setOnSelectedBannerHandle:^(NSInteger index) {
        
        OEAdverModel * model = weakSelf.model.bannerArray[index];
        STWebViewController * vc = [[STWebViewController alloc] initWithUrl:model.link];
        [UIViewController.new.st_currentNavgationController pushViewController:vc animated:YES];
    }];
    [self.pageView setScrollDidScroll:^(NSInteger currentIndex) {
        weakSelf.pageControll.currentPage = currentIndex;
    }];
    [self addSubview:self.pageView];
    
    
    self.pageControll = [[STPageControl alloc] initWithPages:self.pageView.imageUrlArray.count handle:^(NSInteger tag) {
        
    }];
    //    self.pageControll.frame = CGRectMake(0, self.pageView.bottom, 160, 20);
    self.pageControll.bottom = 200 -  25  ;
    self.pageControll.centerX = UIScreenWidth / 2;
    self.pageControll.pageIndicatorTintColor = UIColor.grayColor;
    self.pageControll.currentPageIndicatorTintColor = TM_BlueBackGroundColor;
    [self addSubview:self.pageControll];
}
- (void)layoutSubviews{
    
    self.cateButton.top = self.height - 34;
    [self bringSubviewToFront:self.cateButton];
}
- (void)bindModel:(OEHomeModel *)model indexPath:(NSIndexPath *)indexPath{
    self.model = model;
    [self configBanner];
    if (indexPath.section == 0) {
        self.pageView.hidden = NO;
        self.pageControll.hidden = NO;
        [self.cateButton setTitle:@"Hot Bisiness" forState:UIControlStateNormal];
    }else{
        self.pageView.hidden = YES;
        self.pageControll.hidden = YES;
        [self.cateButton setTitle:@"Hot Offer" forState:UIControlStateNormal];
    }
}
@end
